<?php
/**
 * Author Yulin
 * Email  dwzhanglong@126.com
 * Date   2017-7-21
 * Func   修改密码
 */
defined('IN_YuLin') || exit('NO PERMIT!');

if(!$_uid)
{
	header('Location: '.MU('login'));
	exit;
}

$table = Table('user');

if(IS_POST)
{
	if($a == 'pay')
	{
		$oldpassword = trim($_POST['oldpassword']);
		$newpassword = trim($_POST['newpassword']);
		$newpassword2= trim($_POST['newpassword2']);
		
		if($_Y['user']['paypassword'])
		{
			strlen($oldpassword) < 6 && AjaxReturn(1,'当前密码不正确');
			$password = Password($oldpassword);
			($_Y['user']['paypassword'] != $password) && AjaxReturn(1,'当前密码不正确');
		}
		
		((strlen($newpassword) < 6) || (strlen($newpassword) > 20)) && AjaxReturn(1,'新密码为6-20位');
		($newpassword != $newpassword2) && AjaxReturn(1,'确认密码不正确');
		
		$password = Password($newpassword);
		$db->exec('UPDATE '.$table.' SET paypassword = \''.$password.'\' WHERE id = '.$_uid);
		
		AjaxReturn(0,'修改交易密码成功');
	}
	
	$oldpassword = trim($_POST['oldpassword']);
	$newpassword = trim($_POST['newpassword']);
	$newpassword2= trim($_POST['newpassword2']);
	
	strlen($oldpassword) < 6 && AjaxReturn(1,'当前密码不正确');
	$password = Password($oldpassword);
	($_Y['user']['password'] != $password) && AjaxReturn(1,'当前密码不正确');
	
	((strlen($newpassword) < 6) || (strlen($newpassword) > 20)) && AjaxReturn(1,'新密码为6-20位');
	($newpassword != $newpassword2) && AjaxReturn(1,'确认密码不正确');
	
	$password = Password($newpassword);
	$db->exec('UPDATE '.$table.' SET password = \''.$password.'\' WHERE id = '.$_uid);
	
	AjaxReturn(0,'修改登录密码成功');
}

if($a == 'pay')	//	交易密码
{
	$tpl->display('wap/password_pay');
	exit;
}

$tpl->display('wap/password');